const SysRoleDao = appRequire(`dao/desktop/SysRoleSequelizeDao.js`);
const uuid = require('uuid');
var dateFormat = require("dateformat");
// const SqliteUtil = require('../../modules/SqliteUtil');
class SysRoleService {
    constructor() {

    }
    static async save(role) {
        if (role.id === '' || role.id === undefined) {
            role.id = uuid.v1();
            role.createTime = dateFormat(new Date(), "yyyy-mm-dd HH:MM:ss");
            role.updateTime = role.createTime;
            await SysRoleDao.saveOne(role);
        } else {
            let dbRole = await SysRoleDao.findById(role.id);
            // SqliteUtil.dbObjectToEntity(dbRole,role);
            role.sysRoleAuthIds = role.authIds;
            role.updateTime = dateFormat(new Date(), "yyyy-mm-dd HH:MM:ss");
            await SysRoleDao.updateOne(role);
        }
    }

    static async deleteOne(id) {
        return await SysRoleDao.deleteById(id);
    }

    static async deleteMany(ids) {
        ids = JSON.parse(ids);
        return await SysRoleDao.deleteMany(ids);
    }

    static async findOne(id) {
        return await SysRoleDao.findOne(id);
    }

    static async findAll() {
        return await SysRoleDao.findAll();
    }

    static async findByPage(page) {
        page.pageNum = parseInt(page.pageNum);
        page.pageSize = parseInt(page.pageSize);
        page.searchParams = JSON.parse(page.searchParams);
        return await SysRoleDao.findByPage(page);
    }

}
module.exports = SysRoleService;